package org.zoomdev.zoom.aop.factory;

import org.zoomdev.zoom.aop.FilteredInterceptorFactory;
import org.zoomdev.zoom.aop.Interceptor;
import org.zoomdev.zoom.aop.InterceptorFactory;
import org.zoomdev.zoom.common.filter.MethodFilter;

import java.lang.reflect.Method;
import java.util.List;

public final class ClassAndMethodFilterInterceptorFactory implements FilteredInterceptorFactory {

    private final MethodFilter filter;

    private final InterceptorFactory factory;


    public ClassAndMethodFilterInterceptorFactory(MethodFilter filter, InterceptorFactory factory) {
        this.filter = filter;
        this.factory = factory;
    }

    @Override
    public boolean accept(Class<?> targetClass, Method method) {
        return filter.accept(targetClass, method);
    }

    @Override
    public void createInterceptors(Class<?> targetClass, Method method, List<Interceptor> interceptors) {
        if (filter.accept(targetClass, method)) {
            factory.createInterceptors(targetClass, method, interceptors);
        }
    }
}
